<template>
  <div style="width:100vw;height:100vh;margin: 0 auto;">
    <a-breadcrumb style="height: 30px;background: #fff;">
      <a-breadcrumb-item>
        <router-link to="/">工作台</router-link>
      </a-breadcrumb-item>
      <router-link to="/Searchforrecords">搜索记录</router-link>
    </a-breadcrumb>

    <div style="width:84%;height:150px;background:#fff;margin: 20px 25px;">
      <div
        style="display:flex;
justify-content: space-between;
align-items: center;
height: 110px;
width: 1000px;
padding: 0 40px;
"
      >
        <p>
          类型：
          <input
            type="text"
            style="width:200px;
border: solid 1px #ccc;
outline: none;height: 30px;"
            v-model="name"
            placeholder=" 请输入搜索类型"
          />
        </p>
        <p>
          搜索词：
          <input
            type="text"
            style="width:200px;
border: solid 1px #ccc;
outline: none;height: 30px;"
            v-model="title"
            placeholder=" 请输入搜索词"
          />
        </p>
        <p>
          搜索量：
          <input
            type="text"
            style="width:200px;
border: solid 1px #ccc;
outline: none;height: 30px;"
            v-model="word"
            placeholder=" 请输入搜索量"
          />
        </p>
      </div>

      <div style="display:flex;margin-left: 1050px;">
        <button
          style="padding:3px 15px;background:rgb(39, 105, 227) ;color:#fff;border: none;margin:0 10px;"
          @click="sou()"
        >搜索</button>

        <button
          style="padding:3px 15px;
border: solid 1px #ccc;
background: #fff;"
          @click="chong()"
        >重置</button>
      </div>
    </div>
    <div style="width:84%;height:500px;background: #fff;margin: 20px 25px;">
      <el-table ref="multipleTableRef" :data="list" style="width: 100%">
        <el-table-column type="selection" width="55" />
        <el-table-column label="搜索词" width="330" style="height: 100px;display: block;">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <span style="margin-left: 10px">{{ scope.row.ci }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="搜索量" width="330" style="height: 100px;display: block;">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <span style="margin-left: 10px">{{ scope.row.num }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="搜索时间" width="360">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <span style="margin-left: 10px">{{ scope.row.data }}</span>
            </div>
          </template>
        </el-table-column>

        <el-table-column label="操作">
          <template #default="scope">
            <el-button size="small" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        layout="prev, pager, next"
        :page-size="10"
        :total="length"
        @current-change="changeCode"
      >11</el-pagination>
    </div>
  </div>
</template>

<script lang="ts">


import { defineComponent, onMounted, ref, reactive } from "vue";
import { soulist, sousuo, soudel } from '../../api'
import { message } from "ant-design-vue";



export default defineComponent({

  setup() {
    const name = ref('')
    const title = ref('')
    const word = ref('')
    const list = ref()
    const length = ref('')
    const data = ref('')
    const page = reactive({
      pageCode: 1,
      pageSize: 10
    })
    var d = new Date();  //获取时间
    var hour = d.getHours(); //获取小时
    var minute = d.getMinutes();//获取分 bn
    var second = d.getSeconds();//获取秒
    console.log(d.getFullYear()); //年
    console.log(d.getMonth() + 1);  //月
    console.log(d.getDate())   //日
    console.log(hour, minute, second);  //小时分钟秒
    data.value = '' + d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + ' ' + hour + ':' + minute + ':' + second

    onMounted(() => {
      soulist().then(res => {
        console.log(res);
        list.value = res.data.data.slice((page.pageCode - 1) * page.pageSize, page.pageCode * page.pageSize)
        length.value = res.data.total
      })
    })

    const changeCode = (pageCode: number) => {
      console.log(pageCode);

      page.pageCode = pageCode
      console.log(page);

      soulist().then(res => {
        console.log(res);
        list.value = res.data.data.slice((page.pageCode - 1) * page.pageSize, page.pageCode * page.pageSize)
        length.value = res.data.total

      })

    }
    const chong = () => {
      name.value = ''
      title.value = ''
      word.value = ''
      soulist().then(res => {
        console.log(res);
        list.value = res.data.data
      })
    }
    // 删除
    const handleDelete = (id: any, v: any) => {
      soudel(v).then(res => {
        console.log(res);
        soulist().then(res => {
          console.log(res);
          list.value = res.data.data
        })
      })
    }
    // 搜索
    const sou = () => {
      sousuo({ title, word, data }).then(res => {
        console.log(res);
        list.value = res.data.data
      })
    }
    return {
      name,
      title,
      word,
      list,
      chong,
      handleDelete,
      sou,
      changeCode,
      page,
      length
    }
  }
})

</script>

<style lang='scss' scoped>
.ant-breadcrumb {
  width: 87%;
}
.container,
.el-container,
.el-main {
  width: 85%;
}
</style>